﻿package net.wangit.adm.user;

import net.wangit.MapList;
import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.framework.config.ProjectSettings;
import net.wangit.support.UnitInterceptor;

public class UserUI implements UnitInterceptor {

	public UserUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		MapList userLevels = (MapList) unit.getElement("userlevel").getObject();
		if (ProjectSettings.instance().getSuperUserOption() == 3)
			userLevels.removeRow("value", Integer.toString(3));
		int currentUserLevel = Integer.parseInt(ac.getVisitor().getUser().get(
				"userlevel"));
		for (int i = 0; i < userLevels.size(); i++)
			if (currentUserLevel < userLevels.getRow(i).getInt("value", 1)) {
				userLevels.removeRow(i);
				i--;
			}

		return unit.write(ac);
	}
}
